﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Example2.View
{
    class Camera
    {
        //Höjd och bredd på ritytan
        private int m_screenWidth;
        private int m_screenHeight;

        //Skalorna
        private float m_scaleX, m_scaleY;

        // om vi vill ha en kant(som i labb 1) eller scrolla behöver vi dessa två. 
        private int displacementX = 0;
        private int displacementY = 0;


        //View Frustum Culling

        public Camera(Viewport a_viewport)
        {
            m_screenWidth = a_viewport.Width;
            m_screenHeight = a_viewport.Height;

            //Räkna ut spelets skala
            m_scaleX = (float)m_screenWidth / (float)Model.Level.LEVEL_WIDTH;
            m_scaleY = (float)m_screenHeight / (float)Model.Level.LEVEL_HEIGHT;
        }


        public void focusOn(float modelX, float modelY, float a_timeElapsedSeconds)
        {

        }


        public Vector2 toModelCoordinates(float viewX, float viewY)
        {
            float modelX = (viewX - displacementX) / m_scaleX;
            float modelY = (viewY - displacementY) / m_scaleY;

            return new Vector2(modelX, modelY);
        }

        //Hämta skärmkoordinater från modellkoordinater
        public Vector2 toViewCoordinates(float modelX, float modelY)
        {
            Vector2 view = new Vector2(modelX * m_scaleX + displacementX,
                                       modelY * m_scaleY + displacementY);

            return view; 
        }


        internal float GetScaleX()
        {
            return m_scaleX;
        }

        internal float GetScaleY()
        {
            return m_scaleY;
        }
    }
}
